'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-11-17 09:40:53
'''
#
# @lc app=leetcode.cn id=1030 lang=python3
#
# [1030] 距离顺序排列矩阵单元格
#

# @lc code=start
from typing import List
class Solution:
    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:
        tmp = []
        for i in range(R):
            for j in range(C):
                tmp.append((abs(i-r0)+abs(j-c0), [i, j]))
        tmp.sort()
        ans = []
        for _, v in tmp:
            ans.append(v)
        return ans
# @lc code=end

